Chris Marshall has recently released PDL v2.4.5, a stepping-stone in the Perl Data Language. Chris has led the charge to get cross-platform OpenGL support for PDL. In the past, PDL has used its own GL code, but with Chris's work it now uses Perl's Open GL module, affectionately known as POGL.
You can install PDL from the CPAN without any manual work. However, you'll be missing a lot of goodies, like plotting, OpenGL, and the GSL. In this journal entry, I go through the steps necessary to get PDL installed and working, goodies and all.
The Perl Data Language is a language extension that adds number-crunching and numerical array capabilities to Perl that is on par with C in terms of speed and memory consumption. If you are familiar with IDL or Matlab, think of this as Perl's extension that makes it work essentially like either of those. Having these numerical capabilities is good, but the project is quite complicated and some manual work is probably necessary to get PDL to work the way you'd like. That's what I'll discuss here. I will perform this tutorial using my cpan shell, but hopefully the instrucitons I give will be decent enough that you can perform the installation manually if you cannot use cpan.
Note to ActiveState Perl users: sisyphus (one of the PDL developers/users) has created ppm packages for PDL. I have appended a comment with details, so if this is you, scroll down to the bottom of the page.
Step 0: Install Perl's OpenGL dependencies. The OpenGL module requires freeglut. If you're using Strawberry Perl on Windows, you don't have to do this because POGL (Perl's OpenGL) will download everything it needs. If you're on Linux, you'll need to check your flavor's package manager for it's library or get it from Sourceforge.
Step 1: Install Perl's OpenGL
module. You should be able to get this on cpan without trouble by issuing:
get OpenGL make OpenGL test OpenGL install OpenGLIf you run into trouble, look at the INSTALL file by typing
look OpenGL
in cpan and then examining the file. Hopefully a few manually issued commands
will solve your problem.
If you don't use cpan, you can still get the tarball from cpan's web page. If you download the tarball, you'll need to unpack it somewhere, open a command prompt in the unpacked directory, and issue the following commands:
perl Makefile.PL make make test make installThe last command will probably have to be run with root privileges.
Note that on some platforms, you may need to replace make
with
a similarly named utility. I believe it's dmake
for Strawberry
Perl. If it's not, you probably know who you are and what it's called. I'm sure Google can help. (If you've got ActiveState's Perl, there's a PPM discussed in the comments at the bottom of this post.)
Step 2: Check out the new PDL code (but don't install yet!). From the
cpan shell, simply type get PDL
. If cpan is not available to you, you
can download the source code from
cpan's web page for PDL
or from sourceforge.
Either way, you'll get a tarball that you'll have to open up somewhere.
Step 3: Take care of the prerequisites. As long as you've got a C compiler, PDL should work out-of-the-box. However, you can enable a great deal of optional
functionality by ensuring you've got a few dependencies installed. To figure out what these dependencies are, go to the directory containing the (untarred)
distribution (in cpan, you do that by typing look PDL
) and examine the
DEPENDENCIES file. Make a list of the various dependencies that you'll have
to install. I recommend installing these before you install PDL. Here's an overview of the dependencies that I deem important. To read about all of the dependencies, check out the DEPENDENCIES file. If you have any questions about dependencies I don't discuss here (or about stuff I do discuss here, for that matter), you can send a query to the PDL mailing list, which
you can find here.
(I had GSL and FFTW2 on this list, but it turns out that PDL has its own FFT implementation and does not need FFTW2, and I'm not sure that GSL should come so highly recommended. Don't get me wrong - it's a great library and I've used it before, but I think it would be more appropriate to install it only if you'll actually use it. Don't worry: if you use either of these libraries, you'll have it installed and PDL should detect it and compile the PDL bindings for it.)
Remember: PDL has many other optional features that have their own prerequisites, such as SLATEC and Minuit. Please check the DEPENDENCIES file for details on what's available and what it requires.
Step 4: Install PDL. Now that you've got all the prerequisites out
of the way, go ahead and install PDL. You can use the same commands you used
when you installed POGL above. If you run into trouble here, take a look at
the perldl.conf
file, which will allow you to tweak the
installation process a bit more to your liking.
The build process can take a while, but you'll want to pay attention. The
process automatically detects various libraries. This is particularly important
if it misses an important library for you, in which case you will
probably need to tweak the perldl.conf
file. The file has lots
of internal self-documentation so hopefully you'll be able to figure out what
to try to fix your problem. However, if you run into trouble, check out the
BUGS file for instructions on how to report bugs or other trouble to the PDL
developers.
Step 5: Learn more about PDL. The documentation for PDL isn't great for beginners, but it gets the job done. Check out the wiki, which not only has documentation for PDL but also has links to some good external documentation. If you find some feature to be somewhat under-documented, please let me know and I'll try to tackle it some time in one of my journals. Then, hopefully, I'll propagate the documentation back to the wiki and the POD files.
I hope this helps those of you who have been curious about PDL but have not put in the effort to get it to work. If you have any questions, the readers of the PDL mailing list are usually happy to help. Check here for those email addresses.
I've been meaning to learn more PDL so I can do a quick intro for the students in my department. Mostly as an alternative to Matlab.
I just haven't made the time to learn it and really the plotting part. I think that's what sets matlab apart is the plotting. An ex-grad student did a similar thing with Python (which I might try to pick up but my Python Fu is weak, as it usually is for Perl folks).
Keep the posts coming, you'll have one interested reading.
Every time someone says "No no no no, unlike the rest of CPAN, this one has to be installed by a human" I want to avoid those modules, because if that's the case how will I ever embed that thing in something larger, such that the person installing the larger thing doesn't need to know anything about how it works underneath.
Re:Your description of PDL makes me want to avoid
david m on 2009-10-27T01:34:21
Sure, that's fair. I'm afraid I didn't really stress that you can install PDL from CPAN without doing anything special that I discussed above. (I've edited my original post to reflect this.) PDL's installer will detect if you've got OpenGL or PLplot installed, and skip those steps if it doesn't find it. You really only need to do the special stuff if you want to visualize your data or use the GSL.
You do raise an important point, of course. Suppose you wanted to write a module or program that uses PDL to make plots using PLplot. The installer could then check if you (or your user) has the PLplot libraries installed, and offer to download and build them if you don't. It is quite likely, however, your OS's package manager has a package for the library that PDL wants. Perhaps PDL should learn to detect if you're running Windows, Mac, or Linux, and either download and install the appropriate installer or work through your OS's package manager. Has anybody written a Perl module that can do this? That would be awesome!
Re:Your description of PDL makes me want to avoid
david m on 2009-10-27T05:05:17
Here is a module that checks if your OS has installed some package through its installer instead of directly via cpan, and here is an interface to Debian's apt. I envision something more like the latter, but something that works for many systems so that you could specify a hash like:require_external({
type => 'lib',
name => 'PLplot',
Windows => 'PROGRAM_FILES/plplot/plplot.dll',
Windows_inst => "http://sourceforge...",
Linux => 'plplot.so',
src => "http://sourceforge...",
Ubuntu => libplplot.so',
Ubuntu_inst => "http://getdeb...",
version => 2.1,
# etc, etc
});Then it would call the installer for your OS. If the dependency could be satisfied (specifically, the version requirement) it would make the OS install it. Otherwise, it would download the source and compile it, or download an installer and run it.
Re:Your description of PDL makes me want to avoid
david m on 2009-10-27T02:00:50
Ha! So I just read what you had to say about Chocolate Perl. So you are quite serious when you say you're thinking about including PDL in a bigger project...
As I said, it works out-of-the-box from CPAN. I've dropped a note on the Perldl mailing list about making the installer even smarter, but since a lot of optional PDL stuff depends on external libraries, it would be nice to have some way to interact with the OS and make it install its version of the desired library.
For those of you using ActiveState's ppm, detailed instructions are given in the tarball's win32/INSTALL file. Since you probably won't have much use for said tarball, I've included the lowdown here. If you need more details... I guess you'll have to downlaod that tarball and take a look at the file yourself.
First up install Astro::FITS::Header by running:
ppm install Astro-FITS-Header
Then install the OpenGL, PGPLOT and PDL modules from the uwinnipeg rep by running:
For perl 5.8:
ppm install http://theoryx5.uwinnipeg.ca/ppms/OpenGL.ppd
ppm install http://theoryx5.uwinnipeg.ca/ppms/PGPLOT.ppd
ppm install http://theoryx5.uwinnipeg.ca/ppms/PDL.ppd
Or for perl 5.10:
ppm install http://cpan.uwinnipeg.ca/PPMPackages/10xx/OpenGL.ppd
ppm install http://cpan.uwinnipeg.ca/PPMPackages/10xx/PGPLOT.ppd
ppm install http://cpan.uwinnipeg.ca/PPMPackages/10xx/PDL.ppd
(Note that the ActiveState ppm for PDL currently lacks some of the functionality that is available in the above PDL ppm packages from uwinnipeg.)
The install file also contains more detailed installation instructions for Windows users if you want to customize stuff, so for a different take than what I juts gave here (above, in the original post), check it out!